package com.sixteengroup.personnelms.controller.admin;

import com.github.pagehelper.PageInfo;
import com.sixteengroup.personnelms.bean.log.LoginLog;
import com.sixteengroup.personnelms.bean.log.StaffFlowLog;
import com.sixteengroup.personnelms.service.admin.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(path = "/log")
public class LogController {

    @Autowired
    LogService logService;

    //获取人员流动日志
    @RequestMapping("/getFlowList")
    public Map<String,Object> getFlowList(@RequestBody StaffFlowLog staffFlowLog){
        Map<String,Object> map = new HashMap<>();
        PageInfo<StaffFlowLog> pageInfo = logService.getFlowList(staffFlowLog);
        try {
            map.put("code",200);
            map.put("List",pageInfo.getList());
            map.put("total",pageInfo.getTotal());
        } catch (Exception e){
            map.put("code",500);
            map.put("msg","服务器错误！");
        }
        return map;
    }
    //删除人员流动日志
    @RequestMapping("/deleteFlow/{id}")
    public Map<String,Object> deleteFlow(@PathVariable("id") Integer id){
        Map<String,Object> map = new HashMap<>();
        try {
            logService.deleteFlow(id);
            map.put("code",200);
        }catch (Exception e){
            e.printStackTrace();
            map.put("code",500);
            map.put("msg","服务器错误！");
        }
        return map;
    }
    //查询登录日志
    @RequestMapping("/getLoginList")
    public Map<String,Object> getLoginList(@RequestBody LoginLog loginLog){
        Map<String,Object> map = new HashMap<>();
        PageInfo<LoginLog> pageInfo = logService.getLoginList(loginLog);
        try {
            map.put("code",200);
            map.put("List",pageInfo.getList());
            map.put("total",pageInfo.getTotal());
        } catch (Exception e){
            map.put("code",500);
            map.put("msg","服务器错误！");
        }
        return map;
    }
    //删除登录日志
    @RequestMapping("/deleteLoginlog/{id}")
    public Map<String,Object> deleteLoginlog(@PathVariable("id") Integer id){
        Map<String,Object> map = new HashMap<>();
        try {
            logService.deleteLoginlog(id);
            map.put("code",200);
        }catch (Exception e){
            e.printStackTrace();
            map.put("code",500);
            map.put("msg","服务器错误！");
        }
        return map;
    }

    @RequestMapping("/personInform")
    public Map<String,Object> personInform(){
        Map<String,Object> map = new HashMap<>();
        List<String> part = logService.partInform();
        System.out.println(part.toString());
        List<Integer> number = logService.numberInform();
        System.out.println(number.toString());
        try {
            map.put("part",part);
            map.put("number",number);
        } catch (Exception e){
            map.put("msg","服务器错误！");
        }
        return map;
    }


}
